<!DOCTYPE html>
<html  lang="zh">
<head><link rel=manifest href=/manifest.json>
    <meta charset="utf-8" />

<meta name="generator" content="Hexo 4.1.1" />

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />

 <!-- pwa 配置-->
 <link rel="apple-touch-icon" href="https://cdn.jsdelivr.net/gh/foxhuli229/cdn@1.7/pwa/apple-touch-icon.png">
 <meta name="theme-color" content="white"/>
 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">


<title>JavaScript之再学习 - Fox - Future diary</title>


    <meta name="description" content="概览JavaScript 是一种面向对象的动态语言，它包含类型、运算符、标准内置（ built-in）对象和方法。它的语法来源于 Java 和 C，所以这两种语言的许多语法特性同样适用于 JavaScript。需要注意的一个主要区别是 JavaScript 不支持类，类这一概念在 JavaScript 通过对象原型（object prototype）得到延续。另一个主要区别是 JavaScript">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaScript之再学习">
<meta property="og:url" content="https://foxhuli.top/posts/8f77.html">
<meta property="og:site_name" content="Fox - Future diary">
<meta property="og:description" content="概览JavaScript 是一种面向对象的动态语言，它包含类型、运算符、标准内置（ built-in）对象和方法。它的语法来源于 Java 和 C，所以这两种语言的许多语法特性同样适用于 JavaScript。需要注意的一个主要区别是 JavaScript 不支持类，类这一概念在 JavaScript 通过对象原型（object prototype）得到延续。另一个主要区别是 JavaScript">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://foxhuli.top/images/og_image.png">
<meta property="article:published_time" content="2020-03-12T16:30:00.000Z">
<meta property="article:modified_time" content="2020-03-18T10:39:21.754Z">
<meta property="article:author" content="Fox">
<meta property="article:tag" content="JavaScript">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://foxhuli.top/images/og_image.png">



<link rel="canonical" href="https://foxhuli.top/" />





<link rel="icon" href="https://cdn.jsdelivr.net/gh/foxhuli229/cdn@1.6/images/foxfavicon.png">


<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.7.2/css/bulma.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Ubuntu:400,600|Source+Code+Pro">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@9.12.0/styles/atom-one-dark.css">


    
    
<style>body>.footer,body>.navbar,body>.section{opacity:0}</style>

    
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lightgallery@1.6.8/dist/css/lightgallery.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/css/justifiedGallery.min.css">

    
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.css">

    
    
    
    
<link rel="stylesheet" href="/css/back-to-top.css">

    
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-160296449-1"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());

    gtag('config', 'UA-160296449-1');
</script>

    
    <script>
var _hmt = _hmt || [];
(function() {
    var hm = document.createElement("script");
    hm.src = "//hm.baidu.com/hm.js?14528986";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();
</script>
    
    
    
    <link rel="stylesheet" href="/css/progressbar.css">
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>
    
    <script async="" src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    


<link rel="stylesheet" href="/css/style.css">

<link rel="alternate" href="/atom.xml" title="Fox - Future diary" type="application/atom+xml">
</head>
<body class="is-3-column">
    <nav class="navbar navbar-main">
    <div class="container">
        <div class="navbar-brand is-flex-center">
            <a class="navbar-item navbar-logo" href="/">
                <div>
                    
                        <img src="https://cdn.jsdelivr.net/gh/foxhuli229/cdn@1.5/images/foxlogo.png" alt="JavaScript之再学习" height="28">
                    
                </div>
            </a>
        </div>
        <div class="navbar-menu">
            
            <div class="navbar-start">
                
                <a class="navbar-item"
                href="/">首页</a>
                
                <a class="navbar-item"
                href="/archives">归档</a>
                
                <a class="navbar-item"
                href="/categories">分类</a>
                
                <a class="navbar-item"
                href="/tags">标签</a>
                
                <a class="navbar-item"
                href="/contact">留言板</a>
                
                <a class="navbar-item"
                href="/friends">友情链接</a>
                
                <a class="navbar-item"
                href="/about">关于</a>
                
            </div>
            
            <div class="navbar-end">
                
                
                <a class="navbar-item is-hidden-tablet catalogue" title="目录" href="javascript:;">
                    <i class="fas fa-list-ul"></i>
                </a>
                
                
                <a class="navbar-item search" title="搜索" href="javascript:;">
                    <i class="fas fa-search"></i>
                </a>
                
            </div>
        </div>
    </div>
</nav>
    


    <section class="section">
        <div class="container">
            <div class="columns">
                <div class="column is-8-tablet is-8-desktop is-6-widescreen has-order-2 column-main">
<div class="card">
    
    <div class="card-content article ">
        
        <div class="level article-meta is-size-7 is-uppercase is-mobile is-overflow-x-auto">
            <div class="level-left">
                <time class="level-item has-text-grey" datetime="2020-03-12T16:30:00.000Z">2020-03-13</time>
                
                <div class="level-item">
                <a class="has-link-grey -link" href="/categories/%E5%89%8D%E7%AB%AF/">前端</a>
                </div>
                
                
                <span class="level-item has-text-grey">
                    
                    
                    42 分钟 读完 (大约 6366 个字)
                </span>
                
                
                <span class="level-item has-text-grey" id="busuanzi_container_page_pv">
                    <i class="far fa-eye"></i>
                    的 <span id="busuanzi_value_page_pv">0</span> 次陪伴
                </span>
                
            </div>
        </div>
        
        <h1 class="title is-size-3 is-size-4-mobile has-text-weight-normal">
            
                JavaScript之再学习
            
        </h1>
        <div class="content">
            <h2 id="概览"><a href="#概览" class="headerlink" title="概览"></a>概览</h2><p>JavaScript 是一种面向对象的动态语言，它包含类型、运算符、标准内置（ built-in）对象和方法。它的语法来源于 Java 和 C，所以这两种语言的许多语法特性同样适用于 JavaScript。需要注意的一个主要区别是 JavaScript 不支持类，类这一概念在 JavaScript 通过对象原型（object prototype）得到延续。另一个主要区别是 JavaScript 中的函数也是对象，JavaScript 允许函数在包含可执行代码的同时，能像其他对象一样被传递。<br><a id="more"></a></p>
<h2 id="数据类型和结构"><a href="#数据类型和结构" class="headerlink" title="数据类型和结构"></a>数据类型和结构</h2><h3 id="1-动态类型"><a href="#1-动态类型" class="headerlink" title="1. 动态类型"></a>1. 动态类型</h3><p><code>JavaScript</code>是一种弱类型或者说动态语言。这意味着你不用提前声明变量的类型，在程序运行过程中，类型会被自动确定。这也意味着你可以使用同一个变量保存不同类型的数据：</p>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> foo = <span class="number">42</span>;    <span class="comment">// foo is a Number now</span></span><br><span class="line"><span class="keyword">var</span> foo = <span class="string">"bar"</span>; <span class="comment">// foo is a String now</span></span><br><span class="line"><span class="keyword">var</span> foo = <span class="literal">true</span>;  <span class="comment">// foo is a Boolean now</span></span><br></pre></td></tr></tbody></table></figure>
<h3 id="2-数据类型"><a href="#2-数据类型" class="headerlink" title="2. 数据类型"></a>2. 数据类型</h3><p>最新的<code>ECMAScript</code>标准定义了 7 种数据类型:</p>
<ul>
<li>6 种原始类型<ul>
<li><code>Null</code> (空, 只有一个值<code>null</code>)</li>
<li><code>Undefined</code> (未定义, 一个没有被赋值的变量的默认值是<code>undefined</code>):</li>
<li><code>Boolean</code> (布尔, 可以有两个值：<code>true</code> 和 <code>false</code>)</li>
<li><code>Number</code> (数字)</li>
<li><code>String</code> (字符串)</li>
<li><code>Symbol</code> (符号, ECMAScript 6 新定义的类型，表示独一无二的值)</li>
</ul>
</li>
<li>和 <code>Object</code> (对象)<ul>
<li><code>Function</code> (函数)</li>
<li><code>Array</code> (数组)</li>
<li><code>Date</code> (日期)</li>
<li><code>JSON</code> (JS对象标识,来序列化对象、数组、数值、字符串、布尔值和 <code>null</code>)</li>
<li><code>Math</code> (数学方面的计算)</li>
<li><code>RegExp</code> (正则表达式)</li>
<li><code>Error</code> (错误)</li>
<li><code>Map</code></li>
<li><code>Set</code></li>
</ul>
</li>
</ul>
<h3 id="内置对象"><a href="#内置对象" class="headerlink" title="内置对象"></a>内置对象</h3><p>这里的<strong>内置对象</strong>指的是在全局作用域(<code>global scope</code>)中的对象，由于很多，不再一一列出说明，更全面的解释在<a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects">这里</a>。</p>
<p>全局对象本身可通过<code>this</code>操作符在全局作用域中获得。实际上，全局作用域就是由全局对象的各个属性组成的（包括继承来的属性）。</p>
<h2 id="严格模式"><a href="#严格模式" class="headerlink" title="严格模式"></a>严格模式</h2><p>除了正常运行模式，ECMAscript 5添加了第二种运行模式：”严格模式”（<code>strict mode</code>）。顾名思义，这种模式使得Javascript在更严格的条件下运行。</p>
<p>严格模式可以应用到整个script标签或个别函数中。设立”严格模式”的目的，主要有以下几个：</p>
<ul>
<li>消除 Javascript 语法的一些不合理、不严谨之处，减少一些怪异行为;</li>
<li>消除代码运行的一些不安全之处，保证代码运行的安全；</li>
<li>提高编译器效率，增加运行速度；</li>
<li>为未来新版本的 Javascript 做好铺垫。</li>
</ul>
<h3 id="为某个script标签开启严格模式"><a href="#为某个script标签开启严格模式" class="headerlink" title="为某个script标签开启严格模式"></a>为某个script标签开启严格模式</h3><p>进入严格模式的标志，是下面这行语句：</p>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">'use strict'</span></span><br></pre></td></tr></tbody></table></figure>
<h3 id="为某个函数开启严格模式"><a href="#为某个函数开启严格模式" class="headerlink" title="为某个函数开启严格模式"></a>为某个函数开启严格模式</h3><figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">strict</span>(<span class="params"></span>)</span>{</span><br><span class="line">  <span class="comment">// 函数级别严格模式语法</span></span><br><span class="line"><span class="meta">  'use strict'</span>;</span><br><span class="line">  <span class="keyword">return</span> <span class="string">"I'm a strict mode function!  "</span> + nested();</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">notStrict</span>(<span class="params"></span>) </span>{</span><br><span class="line">    <span class="keyword">return</span> <span class="string">"I'm not strict."</span>;</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
<h2 id="相等性判断"><a href="#相等性判断" class="headerlink" title="相等性判断"></a>相等性判断</h2><p>JavaScript提供三种不同的值比较操作：</p>
<ul>
<li>严格相等 (“triple equals” 或 “identity”)，使用<code>===</code></li>
<li>宽松相等 (“double equals”) ，使用<code>==</code></li>
<li>以及<code>Object.is</code> (ECMAScript 2015/ ES6 新特性)</li>
</ul>
<p>简而言之，在比较两件事情时，双等号将执行类型转换; 三等号将进行相同的比较，而不进行类型转换 (如果类型不同, 只是总会返回 false );  而<code>Object.is</code>的行为方式与三等号相同，但是对于NaN和-0和+0进行特殊处理，所以最后两个不相同，而<code>Object.is(NaN，NaN)</code>将为 true。</p>
<p><img src="https://cdn.jsdelivr.net/gh/foxhuli229/blog-imgs/articles/%E5%89%8D%E7%AB%AF/JavaScript/js_equals.png" alt="各原始类型值的相等比较对照表"></p>
<h2 id="作用域"><a href="#作用域" class="headerlink" title="作用域"></a>作用域</h2><p>作用域就是变量与函数的可访问范围，即作用域控制着变量与函数的可见性和生命周期。在JavaScript中，变量的作用域有<strong>全局作用域</strong>和<strong>局部作用域</strong>两种。</p>
<h3 id="全局作用域"><a href="#全局作用域" class="headerlink" title="全局作用域"></a>全局作用域</h3><p>在代码中任何地方都能访问到的对象拥有全局作用域。一般来说以下几种情形：</p>
<ul>
<li>最外层函数和在最外层函数外面定义的变量拥有全局作用域。</li>
<li>所有未定义而直接赋值的变量自动声明为拥有全局作用域。</li>
<li>所有window对象的属性拥有全局作用域。如：<code>window.name</code>、<code>window.location</code>等。</li>
</ul>
<blockquote>
<p><strong>注</strong>：全局变量存在于程序的整个生命周期。没有块级作用域。</p>
</blockquote>
<h3 id="局部作用域"><a href="#局部作用域" class="headerlink" title="局部作用域"></a>局部作用域</h3><p>局部作用域一般只在固定的代码片段内可访问到，最常见的是在函数内部，所有在一些地方也会看到有人把这种作用域称为<strong>函数作用域</strong>。</p>
<h3 id="作用域链"><a href="#作用域链" class="headerlink" title="作用域链"></a>作用域链</h3><p>JavaScript里一切都是对象。函数对象和其它对象一样，拥有可以通过代码访问的属性和一系列仅供JavaScript引擎访问的内部属性。其中一个内部属性是<code>Scope</code>，该内部属性包含了函数被创建的作用域中对象的集合，这个集合被称为函数的作用域链，它决定了哪些数据能被函数访问。</p>
<p>因为全局变量总是存在于<strong>运行时上下文</strong>作用域链的最末端。所以，在标识符解析的时候，查找全局变量是最慢的。所以，在编写代码的时候应尽量少使用全局变量，尽可能使用局部变量。一个好的经验法则是：<strong>如果一个跨作用域的对象被引用了一次以上，则先把它存储到局部变量里再使用</strong>。</p>
<p><code>with</code>语句主要用来临时扩展作用域链，将语句中的对象添加到作用域的头部。</p>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">person = {<span class="attr">name</span>: <span class="string">"yhb"</span>, <span class="attr">age</span>: <span class="number">22</span>, <span class="attr">height</span>:<span class="number">175</span>, <span class="attr">wife</span>: {<span class="attr">name</span>: <span class="string">"lwy"</span>, <span class="attr">age</span>: <span class="number">21</span>}};</span><br><span class="line"><span class="keyword">with</span> (person.wife) {</span><br><span class="line">    <span class="built_in">console</span>.log(name);</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
<p>with语句将<code>person.wife</code>添加到当前作用域链的头部，所以输出的就是：<code>lwy</code>；with语句结束后，作用域链恢复正常。</p>
<blockquote>
<p>当代码运行到with语句时，运行期上下文的作用域链临时被改变了。一个新的可变对象被创建，它包含了参数指定的对象的所有属性。这个对象将被推入作用域链的头部，这意味着函数的所有局部变量现在处于第二个作用域链对象中，因此访问代价更高了。<br><strong>注</strong>：在程序中应避免使用with语句。</p>
</blockquote>
<h2 id="闭包-Closures"><a href="#闭包-Closures" class="headerlink" title="闭包(Closures)"></a>闭包(Closures)</h2><h3 id="一个示例"><a href="#一个示例" class="headerlink" title="一个示例"></a>一个示例</h3><p>如何从外部读取局部变量？</p>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">f1</span>(<span class="params"></span>) </span>{</span><br><span class="line">    <span class="keyword">var</span> n=<span class="number">999</span>;</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">f2</span>(<span class="params"></span>) </span>{</span><br><span class="line">        alert(n); <span class="comment">// 999</span></span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
<p>在上面的代码中，函数f2就被包括在函数f1内部，这时f1内部的所有局部变量，对f2都是可见的。但是反过来就不行，f2内部的局部变量，对f1就是不可见的。这就是Javascript语言特有的”链式作用域”结构（<code>chain scope</code>），子对象会一级一级地向上寻找所有父对象的变量。所以，<strong>父对象的所有变量，对子对象都是可见的，反之则不成立</strong>。</p>
<p>既然f2可以读取f1中的局部变量，那么只要把f2作为返回值，我们不就可以在f1外部读取它的内部变量了吗！</p>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">f1</span>(<span class="params"></span>) </span>{</span><br><span class="line">    <span class="keyword">var</span> n=<span class="number">999</span>;</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">f2</span>(<span class="params"></span>) </span>{</span><br><span class="line">        alert(n); <span class="comment">// 999</span></span><br><span class="line">    }</span><br><span class="line">    <span class="keyword">return</span> f2;</span><br><span class="line">}</span><br><span class="line"><span class="keyword">var</span> result=f1();</span><br><span class="line">result(); <span class="comment">// 999</span></span><br></pre></td></tr></tbody></table></figure>
<h3 id="闭包解释"><a href="#闭包解释" class="headerlink" title="闭包解释"></a>闭包解释</h3><blockquote>
<p><strong>闭包定义</strong>：闭包是一个函数和函数所声明的词法环境的结合。</p>
</blockquote>
<p>在上面的代码中，f2函数就是闭包。<strong>闭包</strong>（<code>closure</code>）定义非常抽象，很难看懂。我的理解是，<strong>闭包就是能够读取其他函数内部变量的函数</strong>。在本质上，闭包就是将函数内部和函数外部连接起来的一座桥梁。</p>
<p>闭包最大用处有两个，一个是可以读取函数内部的变量，另一个就是让这些变量的值始终保持在内存中，不会在调用结束后被垃圾回收机制（<code>garbage collection</code>）回收。</p>
<h3 id="立即执行函数表达式"><a href="#立即执行函数表达式" class="headerlink" title="立即执行函数表达式"></a>立即执行函数表达式</h3><p>有时你想模拟一个模拟块级作用域，例如你想将变量从全局作用域隔离。完成这个工作的模式叫做<code>IIFE</code>(立即执行函数表达式(<code>Immediately Invoked Function Expression</code>))：</p>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>{  <span class="comment">// 块开始</span></span><br><span class="line">    <span class="keyword">var</span> tmp = ...;  <span class="comment">// 非全局变量</span></span><br><span class="line">}());  <span class="comment">// 块结束</span></span><br></pre></td></tr></tbody></table></figure>
<h3 id="用闭包模拟私有方法"><a href="#用闭包模拟私有方法" class="headerlink" title="用闭包模拟私有方法"></a>用闭包模拟私有方法</h3><p>JavaScript 并不提供原生的支持私有方法，但是可以使用闭包模拟私有方法。私有方法不仅仅有利于限制对代码的访问：还提供了管理全局命名空间的强大能力，避免非核心的方法弄乱了代码的公共接口部分。</p>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> Counter = (<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</span><br><span class="line">    <span class="keyword">var</span> privateCounter = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">changeBy</span>(<span class="params">val</span>) </span>{</span><br><span class="line">        privateCounter += val;</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> {</span><br><span class="line">        increment: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</span><br><span class="line">            changeBy(<span class="number">1</span>);</span><br><span class="line">        },</span><br><span class="line">        decrement: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</span><br><span class="line">            changeBy(<span class="number">-1</span>);</span><br><span class="line">        },</span><br><span class="line">        value: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</span><br><span class="line">            <span class="keyword">return</span> privateCounter;</span><br><span class="line">        }</span><br><span class="line">    }</span><br><span class="line">})();</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(Counter.value()); <span class="comment">/* logs 0 */</span></span><br><span class="line">Counter.increment();</span><br><span class="line">Counter.increment();</span><br><span class="line"><span class="built_in">console</span>.log(Counter.value()); <span class="comment">/* logs 2 */</span></span><br><span class="line">Counter.decrement();</span><br><span class="line"><span class="built_in">console</span>.log(Counter.value()); <span class="comment">/* logs 1 */</span></span><br></pre></td></tr></tbody></table></figure>
<p>上面创建了一个环境，为三个函数所共享：<code>Counter.increment</code>, <code>Counter.decrement</code>和<code>Counter.value</code>。该共享环境创建于一个匿名函数体内，该函数一经定义立刻执行。环境中包含两个私有项：名为<code>privateCounter</code>的变量和名为<code>changeBy</code>的函数。这两项都无法在匿名函数外部直接访问。必须通过匿名包装器返回的三个公共函数访问。</p>
<p><strong>注意</strong>：</p>
<ul>
<li>由于闭包会使得函数中的变量都被保存在内存中，内存消耗很大，所以不能滥用闭包，否则会造成网页的性能问题，在IE中可能导致内存泄露。解决方法是，在退出函数之前，将不使用的局部变量全部删除。</li>
<li>闭包会在父函数外部，改变父函数内部变量的值。所以，如果你把父函数当作对象（object）使用，把闭包当作它的公用方法（Public Method），把内部变量当作它的私有属性（private value），这时一定要小心，不要随便改变父函数内部变量的值。</li>
</ul>
<h2 id="内存机制"><a href="#内存机制" class="headerlink" title="内存机制"></a>内存机制</h2><p>首先JavaScript中的变量分为<strong>基本类型</strong>和<strong>引用类型</strong>。</p>
<ul>
<li>基本类型就是保存在栈内存中的简单数据段。基本类型有<code>Undefined</code>、<code>Null</code>、<code>Boolean</code>、<code>Number</code>和<code>String</code>。这些类型在内存中分别占有固定大小的空间，他们的值保存在<strong>栈空间</strong>，我们通过按值来访问的。</li>
<li>引用类型指的是那些保存在堆内存中的对象。引用类型，值大小不固定，栈内存中存放地址指向堆内存中的对象。是按引用访问的。栈内存中存放的只是该对象的访问地址，在堆内存中为这个值分配空间。</li>
</ul>
<h3 id="为什么会有栈内存和堆内存之分"><a href="#为什么会有栈内存和堆内存之分" class="headerlink" title="为什么会有栈内存和堆内存之分"></a>为什么会有栈内存和堆内存之分</h3><p>与垃圾回收机制有关，为了使程序运行时占用的内存最小。</p>
<p>当一个方法执行时，每个方法都会建立自己的内存栈，在这个方法内定义的变量将会逐个放入这块栈内存里，随着方法的执行结束，这个方法的内存栈也将自然销毁了。因此，所有在方法中定义的变量都是放在栈内存中的；</p>
<p>当我们在程序中创建一个对象时，这个对象将被保存到运行时数据区中，以便反复利用（因为对象的创建成本通常较大），这个运行时数据区就是堆内存。堆内存中的对象不会随方法的结束而销毁，即使方法结束后，这个对象还可能被另一个引用变量所引用（方法的参数传递时很常见），则这个对象依然不会被销毁，只有当一个对象没有任何引用变量引用它时，系统的垃圾回收机制才会在核实的时候回收它。</p>
<h3 id="垃圾回收机制"><a href="#垃圾回收机制" class="headerlink" title="垃圾回收机制"></a>垃圾回收机制</h3><p>Javascript具有自动垃圾回收机制(<code>GC</code>:<code>Garbage Collecation</code>)，也就是说，执行环境会负责管理代码执行过程中使用的内存。</p>
<p>JavaScript垃圾回收的机制很简单：<strong>找出不再使用的变量，然后释放掉其占用的内存，但是这个过程不是实时的，因为其开销比较大，所以垃圾回收器会按照固定的时间间隔周期性的执行</strong>。</p>
<p>不再使用的变量也就是生命周期结束的变量，当然只可能是局部变量，全局变量的生命周期直至浏览器卸载页面才会结束。局部变量只在函数的执行过程中存在，而在这个过程中会为局部变量在栈或堆上分配相应的空间，以存储它们的值，然后在函数中使用这些变量，直至函数结束，而闭包中由于内部函数的原因，外部函数并不能算是结束。</p>
<h4 id="清除方式"><a href="#清除方式" class="headerlink" title="清除方式"></a>清除方式</h4><ul>
<li><strong>标记清除</strong>：垃圾回收器在运行的时候会给存储在内存中的所有变量都加上标记。然后，它会去掉环境中的变量以及被环境中的变量引用的变量的标记（闭包）。而在此之后再被加上标记的变量将被视为准备删除的变量，原因是环境中的变量已经无法访问到这些变量了。最后，垃圾回收器完成内存清除工作，销毁那些带标记的值并回收它们所占用的内存空间。</li>
<li><strong>引用计数</strong>：引用计数的含义是跟踪记录每个值被引用的次数。当声明了一个变量并将一个引用类型值赋给该变量时，则这个值的引用次数就是1。如果同一个值又被赋给另一个变量，则该值的引用次数加1。相反，如果包含对这个值引用的变量又取得了另外一个值，则这个值的引用次数减1。当这个值的引用次数变成0时，则说明没有办法再访问这个值了，因而就可以将其占用的内存空间回收回来。这样，当垃圾回收器下次再运行时，它就会释放那些引用次数为0的值所占用的内存。</li>
</ul>
<h2 id="原型-prototype"><a href="#原型-prototype" class="headerlink" title="原型(prototype)"></a>原型(prototype)</h2><p>原型是一个对象，其他对象可以通过它实现属性继承。JavaScript的对象中都包含了一个<code>Prototype</code>内部属性，这个属性所对应的就是该对象的原型。<code>Prototype</code>作为对象的内部属性，是不能被直接访问的。所以为了方便查看一个对象的原型，Firefox和Chrome中提供了<code>__proto__</code>这个非标准的访问器。</p>
<ul>
<li>所有的对象都有<code>__proto__</code>属性，该属性对应着该对象的原型。</li>
<li>所有的函数对象都有<code>prototype</code>属性，该属性的值会被赋值给该函数创建的对象的<code>__proto__</code>属性</li>
<li>所有的原型对象都有<code>constructor</code>属性，该属性对应创建所有指向该原型的实例的构造函数</li>
<li>函数对象和原型对象通过<code>prototype</code>和<code>constructor</code>属性进行相互关联</li>
<li><code>Object</code>实例对象的原型<code>obj.__proto__</code>就是<code>Object.prototype</code></li>
<li><code>hasOwnProperty</code>是<code>Object.prototype</code>的一个方法，该方法能判断一个对象是否包含自定义属性而不是原型链上的属性，因为”hasOwnProperty” 是 JavaScript 中唯一一个处理属性但是不查找原型链的函数</li>
</ul>
<h3 id="原型链"><a href="#原型链" class="headerlink" title="原型链"></a>原型链</h3><p>因为每个对象和原型都有原型，对象的原型指向对象的父，而父的原型又指向父的父，这种原型层层连接起来的就构成了原型链。</p>
<p>当通过原型链查找一个属性的时候，首先查找的是对象本身的属性，如果找不到才会继续按照原型链进行查找。这样一来，如果想要覆盖原型链上的一些属性，我们就可以直接在对象中引入这些属性，达到属性隐藏的效果。</p>
<h2 id="对象创建方式"><a href="#对象创建方式" class="headerlink" title="对象创建方式"></a>对象创建方式</h2><h3 id="1-Object构造函数方式"><a href="#1-Object构造函数方式" class="headerlink" title="1. Object构造函数方式"></a>1. Object构造函数方式</h3><figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> Person = <span class="keyword">new</span> <span class="built_in">Object</span>();</span><br><span class="line">Person.name = <span class="string">'Nike'</span>;</span><br><span class="line">Person.age = <span class="number">29</span>;</span><br></pre></td></tr></tbody></table></figure>
<p>这行代码创建了<code>Object</code>引用类型的一个新实例，然后把实例保存在变量<code>Person</code>中。</p>
<h3 id="2-对象字面量方式"><a href="#2-对象字面量方式" class="headerlink" title="2. 对象字面量方式"></a>2. 对象字面量方式</h3><figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> Person = {</span><br><span class="line"> name: <span class="string">'Nike'</span>;</span><br><span class="line"> age: <span class="number">29</span>;</span><br><span class="line">};</span><br></pre></td></tr></tbody></table></figure>
<p>对象字面量是对象定义的一种简写形式，目的在于简化创建包含大量属性对象的过程。</p>
<blockquote>
<p><strong>注</strong>：前两种方法的缺点在于：它们都是用了同一个接口创建很多对象，会产生大量的重复代码，就是如果你有100个对象，那你要输入100次很多相同的代码。那我们有什么方法来避免过多的重复代码呢，就是把创建对象的过程封装在函数体内，通过函数的调用直接生成对象。</p>
</blockquote>
<h3 id="3-工厂模式"><a href="#3-工厂模式" class="headerlink" title="3. 工厂模式"></a>3. 工厂模式</h3><figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">createPerson</span>(<span class="params">name, age, job</span>) </span>{</span><br><span class="line">    <span class="keyword">var</span> o = <span class="keyword">new</span> <span class="built_in">Object</span>();</span><br><span class="line">    o.name = name;</span><br><span class="line">    o.age = age;</span><br><span class="line">    o.job = job;</span><br><span class="line">    o.sayName = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</span><br><span class="line">        alert(<span class="keyword">this</span>.name);</span><br><span class="line">    };</span><br><span class="line">    <span class="keyword">return</span> o;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> person1 = createPerson(<span class="string">'Nike'</span>, <span class="number">29</span>, <span class="string">'teacher'</span>);</span><br></pre></td></tr></tbody></table></figure>
<p>在使用工厂模式创建对象的时候，我们都可以注意到，在<code>createPerson</code>函数中，返回的是一个对象。但我们就无法判断返回的对象究竟是一个什么样的类型。于是就出现了第四种创建对象的模式。</p>
<h3 id="4-构造函数方式"><a href="#4-构造函数方式" class="headerlink" title="4. 构造函数方式"></a>4. 构造函数方式</h3><figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Person</span>(<span class="params">name, age, job</span>) </span>{</span><br><span class="line">    <span class="keyword">this</span>.name = name;</span><br><span class="line">    <span class="keyword">this</span>.age = age;</span><br><span class="line">    <span class="keyword">this</span>.job = job;</span><br><span class="line">    <span class="keyword">this</span>.sayName = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</span><br><span class="line">        alert(<span class="keyword">this</span>.name);</span><br><span class="line">    };</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> person1 = <span class="keyword">new</span> Person(<span class="string">'Nike'</span>, <span class="number">29</span>, <span class="string">'teacher'</span>);</span><br><span class="line">alert(person1 <span class="keyword">instanceof</span> <span class="built_in">Object</span>); <span class="comment">//ture</span></span><br></pre></td></tr></tbody></table></figure>
<p>对比工厂模式，我们可以发现以下区别：</p>
<ul>
<li>没有显示地创建对象</li>
<li>直接将属性和方法赋给了<code>this</code>对象</li>
<li>没有<code>return</code>语句</li>
<li>终于可以识别的对象的类型。对于检测对象类型，我们应该使用instanceof操作符，我们来进行自主检测：</li>
</ul>
<p>那么构造函数确实挺好用的，但是它也有它的缺点：就是每个方法都要在每个实例上重新创建一遍，方法指的就是我们在对象里面定义的函数。如果方法的数量很多，就会占用很多不必要的内存。于是出现了第五种创建对象的方法。</p>
<h3 id="5-原型创建对象模式"><a href="#5-原型创建对象模式" class="headerlink" title="5. 原型创建对象模式"></a>5. 原型创建对象模式</h3><figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Person</span>(<span class="params"></span>)</span>{}</span><br><span class="line">Person.prototype.name = <span class="string">'Nike'</span>;</span><br><span class="line">Person.prototype.age = <span class="number">20</span>;</span><br><span class="line">Person.prototype.jbo = <span class="string">'teacher'</span>;</span><br><span class="line">Person.prototype.sayName = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</span><br><span class="line">    alert(<span class="keyword">this</span>.name);</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> person1 = <span class="keyword">new</span> Person();</span><br><span class="line"><span class="keyword">var</span> person2 = <span class="keyword">new</span> Person();</span><br><span class="line">person1.name = <span class="string">'Greg'</span>;</span><br><span class="line">alert(person1.name); <span class="comment">//'Greg' --来自实例</span></span><br><span class="line">alert(person2.name); <span class="comment">//'Nike' --来自原型</span></span><br></pre></td></tr></tbody></table></figure>
<p>当为对象实例添加一个属性时，这个属性就会屏蔽原型对象中保存的同名属性。</p>
<p>这时候我们就可以使用构造函数模式与原型模式结合的方式，构造函数模式用于定义实例属性，而原型模式用于定义方法和共享的属性。</p>
<h3 id="6-组合使用构造函数模式和原型模式"><a href="#6-组合使用构造函数模式和原型模式" class="headerlink" title="6. 组合使用构造函数模式和原型模式"></a>6. 组合使用构造函数模式和原型模式</h3><figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Person</span>(<span class="params">name, age, job</span>) </span>{</span><br><span class="line">    <span class="keyword">this</span>.name = name;</span><br><span class="line">    <span class="keyword">this</span>.age = age;</span><br><span class="line">    <span class="keyword">this</span>.job = job;</span><br><span class="line">}</span><br><span class="line">Person.prototype = {</span><br><span class="line">    <span class="keyword">constructor</span>: Person,</span><br><span class="line">    sayName: function(){</span><br><span class="line">        alert(<span class="keyword">this</span>.name);</span><br><span class="line">    };</span><br><span class="line">}</span><br><span class="line"><span class="keyword">var</span> person1 = <span class="keyword">new</span> Person(<span class="string">'Nike'</span>, <span class="number">20</span>, <span class="string">'teacher'</span>);</span><br></pre></td></tr></tbody></table></figure>
<h3 id="7-动态原型模式"><a href="#7-动态原型模式" class="headerlink" title="7. 动态原型模式"></a>7. 动态原型模式</h3><figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Person</span>(<span class="params">name, age, job</span>) </span>{</span><br><span class="line">    <span class="keyword">this</span>.name = name;</span><br><span class="line">    <span class="keyword">this</span>.age = age;</span><br><span class="line">    <span class="keyword">this</span>.job = job;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="keyword">this</span>.sayName != <span class="string">'function'</span>) {</span><br><span class="line">        Person.prototype.sayName = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</span><br><span class="line">            alert(<span class="keyword">this</span>.name);</span><br><span class="line">        }</span><br><span class="line">    }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> person1 = <span class="keyword">new</span> Person(<span class="string">'Nike'</span>, <span class="number">20</span>, <span class="string">'teacher'</span>);</span><br><span class="line">person1.sayName();</span><br></pre></td></tr></tbody></table></figure>
<p>动态原型模式将所有信息封装在了构造函数中，而通过构造函数中初始化原型（仅第一个对象实例化时初始化原型），这个可以通过判断该方法是否有效而选择是否需要初始化原型。</p>
<h3 id="8-寄生构造函数方式"><a href="#8-寄生构造函数方式" class="headerlink" title="8. 寄生构造函数方式"></a>8. 寄生构造函数方式</h3><figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Person</span>(<span class="params">name, age, job</span>) </span>{</span><br><span class="line">    <span class="keyword">var</span> o = <span class="keyword">new</span> <span class="built_in">Object</span>();</span><br><span class="line">    o.name = name;</span><br><span class="line">    o.age = age;</span><br><span class="line">    o.job = job;</span><br><span class="line">    o.sayName = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</span><br><span class="line">        alert(<span class="keyword">this</span>.name);</span><br><span class="line">    };</span><br><span class="line">    <span class="keyword">return</span> o;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> person1 = <span class="keyword">new</span> Person(<span class="string">'Nike'</span>, <span class="number">29</span>, <span class="string">'teacher'</span>);</span><br></pre></td></tr></tbody></table></figure>
<p>寄生模式和工厂模式几乎一样，寄生模式和工厂模式的区别：</p>
<ul>
<li>寄生模式创建对象时使用了<code>new</code>关键字</li>
<li>寄生模式的外部包装函数是一个构造函数</li>
</ul>
<blockquote>
<p><strong>作用</strong>:寄生模式可以在特殊的情况下为对象来创建构造函数,原因在于我们可以通过构造函数重写对象的值，并通过return返回。重写调用构造函数(创建的对象的实例)之后的对象实例的新的值。</p>
</blockquote>
<h3 id="9-稳妥构造函数方式"><a href="#9-稳妥构造函数方式" class="headerlink" title="9. 稳妥构造函数方式"></a>9. 稳妥构造函数方式</h3><figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Person</span>(<span class="params">name, age, job</span>) </span>{</span><br><span class="line">    <span class="keyword">var</span> o = <span class="keyword">new</span> <span class="built_in">Object</span>();</span><br><span class="line">    o.sayName = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</span><br><span class="line">        alert(<span class="keyword">this</span>.name);</span><br><span class="line">    };</span><br><span class="line">    <span class="keyword">return</span> o;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> person = <span class="keyword">new</span> Person(<span class="string">'Nike'</span>, <span class="number">29</span>, <span class="string">'teacher'</span>);</span><br><span class="line">person.sayName(); <span class="comment">// 使用稳妥构造函数模式只能通过其构造函数内部的方法来获取里面的属性值</span></span><br></pre></td></tr></tbody></table></figure>
<p>道格拉斯·克拉克福德发明了JavaScript中的稳妥对象这个概念。所谓稳妥对象，是指没有公共属性，而且其方法也不引用<code>this</code>对象。稳妥对象最适合在一些安全环境中（这些环境会禁止使用<code>this</code>和<code>new</code>），或者在防止数据被其他应用程序改动时使用。稳妥构造函数遵循的与寄生构造函数类似的模式，但又两点不同：</p>
<ul>
<li>一是新创建对象的实例方法不引用<code>this</code>；</li>
<li>二是不使用<code>new</code>操作符调用构造函数。</li>
</ul>
<blockquote>
<p><strong>注</strong>：与寄生构造函数模式类似，使用稳妥构造函数模式创建的对象与构造函数之间没有什么关系，因此instanceof操作符对这种对象也没有意义。</p>
</blockquote>
<h2 id="并发模型和事件循环-event-loop"><a href="#并发模型和事件循环-event-loop" class="headerlink" title="并发模型和事件循环(event loop)"></a>并发模型和事件循环(event loop)</h2><p>JavaScript 的并发模型基于<strong>事件循环</strong>。</p>
<p><img src="https://cdn.jsdelivr.net/gh/foxhuli229/blog-imgs/articles/%E5%89%8D%E7%AB%AF/JavaScript/js_event.png" alt="Js堆栈队列图"></p>
<h3 id="1-运行时概念"><a href="#1-运行时概念" class="headerlink" title="1. 运行时概念"></a>1. 运行时概念</h3><h4 id="栈"><a href="#栈" class="headerlink" title="栈"></a>栈</h4><p>函数调用形成了一个栈帧。</p>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">foo</span>(<span class="params">b</span>) </span>{</span><br><span class="line">  <span class="keyword">var</span> a = <span class="number">10</span>;</span><br><span class="line">  <span class="keyword">return</span> a + b + <span class="number">11</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">bar</span>(<span class="params">x</span>) </span>{</span><br><span class="line">  <span class="keyword">var</span> y = <span class="number">3</span>;</span><br><span class="line">  <span class="keyword">return</span> foo(x * y);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(bar(<span class="number">7</span>));</span><br></pre></td></tr></tbody></table></figure>
<p>当调用 bar 时，创建了第一个帧 ，帧中包含了 bar 的参数和局部变量。当 bar 调用 foo 时，第二个帧就被创建，并被压到第一个帧之上，帧中包含了 foo 的参数和局部变量。当 foo 返回时，最上层的帧就被弹出栈（剩下 bar 函数的调用帧 ）。当 bar 返回的时候，栈就空了。</p>
<h4 id="堆"><a href="#堆" class="headerlink" title="堆"></a>堆</h4><p>对象被分配在一个堆中，即用以表示一个大部分非结构化的内存区域。</p>
<h4 id="队列"><a href="#队列" class="headerlink" title="队列"></a>队列</h4><p>一个 JavaScript 运行时包含了一个待处理的消息队列。每一个消息都与一个函数相关联。当栈拥有足够内存时，从队列中取出一个消息进行处理。这个处理过程包含了调用与这个消息相关联的函数（以及因而创建了一个初始堆栈帧）。当栈再次为空的时候，也就意味着消息处理结束。</p>
<h3 id="2-事件循环"><a href="#2-事件循环" class="headerlink" title="2. 事件循环"></a>2. 事件循环</h3><p>之所以称为<strong>事件循环</strong>，是因为它经常被用于类似如下的方式来实现：</p>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">while</span> (queue.waitForMessage()) {</span><br><span class="line">  queue.processNextMessage();</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
<p>如果当前没有任何消息，queue.waitForMessage 会等待着同步将要到来的消息。</p>
<p>每一个消息完整的执行后，其它消息才会被执行。这个模型的一个缺点在于当一个消息的完成耗时过长，网络应用无法处理用户的交互如点击或者滚动。浏览器用“程序需要过长时间运行”的对话框来缓解这个问题。一个比较好的解决方案是使消息处理变短且如果可能的话，将一个消息拆分成几个消息。</p>
<p>在浏览器里，当一个事件出现且有一个事件监听器被绑定时，消息会被随时添加。如果没有事件监听器，事件会丢失。所以点击一个附带点击事件处理函数的元素会添加一个消息。其它事件亦然。</p>
<h3 id="3-绝不阻塞"><a href="#3-绝不阻塞" class="headerlink" title="3. 绝不阻塞"></a>3. 绝不阻塞</h3><p>事件循环(event loop)模型特性在于它<strong>永不阻塞</strong>。通常由事件或者回调函数进行 I/O (input/output)处理 。</p>
<hr>
<p>参考文档：</p>
<ul>
<li><a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript">MDN</a></li>
</ul>
<script>
        document.querySelectorAll('.github-emoji')
          .forEach(el => {
            if (!el.dataset.src) { return; }
            const img = document.createElement('img');
            img.style = 'display:none !important;';
            img.src = el.dataset.src;
            img.addEventListener('error', () => {
              img.remove();
              el.style.color = 'inherit';
              el.style.backgroundImage = 'none';
              el.style.background = 'none';
            });
            img.addEventListener('load', () => {
              img.remove();
            });
            document.body.appendChild(img);
          });
      </script>
        </div>
        
        <div class="level is-size-7 is-uppercase">
            <div class="level-start">
                <div class="level-item">
                    <span class="is-size-6 has-text-grey has-mr-7">#</span>
                    <a class="has-link-grey -link" href="/tags/JavaScript/" rel="tag">JavaScript</a>
                </div>
            </div>
        </div>
        
        
        
        <div class="social-share"></div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js@1.0.16/dist/css/share.min.css">
<script src="https://cdn.jsdelivr.net/npm/social-share.js@1.0.16/dist/js/social-share.min.js"></script>
        
    </div>
</div>



<div class="card">
    <div class="card-content">
        <h3 class="menu-label has-text-centered">喜欢这篇文章？打赏一下作者吧</h3>
        <div class="buttons is-centered">
            
                
<a class="button is-info donate">
    <span class="icon is-small">
        <i class="fab fa-alipay"></i>
    </span>
    <span>支付宝</span>
    <div class="qrcode"><img src="https://cdn.jsdelivr.net/gh/foxhuli229/cdn@1.1/images/zalipay.jpg" alt="支付宝"></div>
</a>

                
                
<a class="button is-success donate">
    <span class="icon is-small">
        <i class="fab fa-weixin"></i>
    </span>
    <span>微信</span>
    <div class="qrcode"><img src="https://cdn.jsdelivr.net/gh/foxhuli229/cdn@1.1/images/zweixinplay.jpg" alt="微信"></div>
</a>

                
        </div>
    </div>
</div>



<div class="card card-transparent">
    <div class="level post-navigation is-flex-wrap is-mobile">
        
        <div class="level-start">
            <a class="level level-item has-link-grey  article-nav-prev" href="/posts/cdf9.html">
                <i class="level-item fas fa-chevron-left"></i>
                <span class="level-item">JavaScript基础教程</span>
            </a>
        </div>
        
        
        <div class="level-end">
            <a class="level level-item has-link-grey  article-nav-next" href="/posts/225f.html">
                <span class="level-item">Array数组</span>
                <i class="level-item fas fa-chevron-right"></i>
            </a>
        </div>
        
    </div>
</div>



<div class="card">
    <div class="card-content">
        <h3 class="title is-5 has-text-weight-normal">评论</h3>
        
<div id="valine-thread" class="content"></div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js"></script>
<script>
    new Valine({
        el: '#valine-thread' ,
        notify: false,
        verify: true,
        app_id: 'LliwJqiOd8MS79CDFo9tGFEX-gzGzoHsz',
        app_key: '05cdCDsmfHxxo8UIOvcDFaq5',
        placeholder: 'just go go'
    });
</script>

    </div>
</div>
</div>
                
    

    

    

    


    <div class="column 11 is-4-tablet is-4-desktop is-3-widescreen  has-order-1 column-left ">
        
        
<!-- 个人资料 -->
<div class="card widget">
    <div class="card-content">
        <nav class="level">
            <div class="level-item has-text-centered" style="flex-shrink: 1">
                <div>
                    
                    
                    <figure class="image is-128x128 has-mb-6">
                        <img class="is-rounded" src="https://cdn.jsdelivr.net/gh/foxhuli229/cdn@1.4/images/z_avater.png"
                            alt="Fox"
                            style="">
                    </figure>
                    
                    <p class="is-size-4 is-block">
                        Fox
                    </p>
                    
                    
                    
                    <p class="is-size-6 is-flex is-flex-center has-text-grey">
                        <i class="fas fa-map-marker-alt has-mr-7"></i>
                        <span>chengdu - china</span>
                    </p>
                    
                </div>
            </div>
        </nav>
        <nav class="level is-mobile">
            <div class="level-item has-text-centered is-marginless">
                <div>
                    <p class="heading">
                        文章
                    </p>
                    <a href="/archives">
                        <p class="title has-text-weight-normal">
                            17
                        </p>
                    </a>
                </div>
            </div>
            <div class="level-item has-text-centered is-marginless">
                <div>
                    <p class="heading">
                        分类
                    </p>
                    <a href="/categories">
                        <p class="title has-text-weight-normal">
                            5
                        </p>
                    </a>
                </div>
            </div>
            <div class="level-item has-text-centered is-marginless">
                <div>
                    <p class="heading">
                        标签
                    </p>
                    <a href="/tags">
                        <p class="title has-text-weight-normal">
                            13
                        </p>
                    </a>
                </div>
            </div>
        </nav>
        
        <div class="level">
            <a class="level-item button is-link is-rounded" href="https://github.com/foxhuli229" target="_blank"
                rel="noopener">
                关注我</a>
        </div>
        
        
        
        <div class="level is-mobile">
            
            <a class="level-item button is-white is-marginless" target="_blank" rel="noopener" title="Github"
                href="https://github.com/foxhuli229">
                
                <i class="fab fa-github"></i>
                
            </a>
            
            <a class="level-item button is-white is-marginless" target="_blank" rel="noopener" title="Facebook"
                href="https://facebook.com">
                
                <i class="fab fa-facebook"></i>
                
            </a>
            
            <a class="level-item button is-white is-marginless" target="_blank" rel="noopener" title="Twitter"
                href="https://twitter.com">
                
                <i class="fab fa-twitter"></i>
                
            </a>
            
            <a class="level-item button is-white is-marginless" target="_blank" rel="noopener" title="Dribbble"
                href="https://dribbble.com">
                
                <i class="fab fa-dribbble"></i>
                
            </a>
            
            <a class="level-item button is-white is-marginless" target="_blank" rel="noopener" title="RSS"
                href="/">
                
                <i class="fas fa-rss"></i>
                
            </a>
            
        </div>
        
    </div>
</div>
        
        
<div class="card widget">
    <div class="card-content">
        <div class="menu">
            <h3 class="menu-label">
                分类
            </h3>
            <ul class="menu-list">
            <li>
        <a class="level is-marginless" href="/categories/hexo/">
            <span class="level-start">
                <span class="level-item">hexo</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">1</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/categories/vue/">
            <span class="level-start">
                <span class="level-item">vue</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">3</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/categories/%E5%89%8D%E7%AB%AF/">
            <span class="level-start">
                <span class="level-item">前端</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">12</span>
            </span>
        </a><ul><li>
        <a class="level is-marginless" href="/categories/%E5%89%8D%E7%AB%AF/vue/">
            <span class="level-start">
                <span class="level-item">vue</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">1</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/categories/%E5%89%8D%E7%AB%AF/%E9%9D%A2%E8%AF%95/">
            <span class="level-start">
                <span class="level-item">面试</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">4</span>
            </span>
        </a></li></ul></li>
            </ul>
        </div>
    </div>
</div>
        
        <div class="card widget">
    <div class="card-content">
        <div class="menu">
            <h3 class="menu-label">
                标签
            </h3>
            <div class="field is-grouped is-grouped-multiline">
                
                <div class="control">
                    <a class="tags has-addons" href="/tags/JavaScript/">
                        <span class="tag">JavaScript</span>
                        <span class="tag is-grey">5</span>
                    </a>
                </div>
                
                <div class="control">
                    <a class="tags has-addons" href="/tags/SVG/">
                        <span class="tag">SVG</span>
                        <span class="tag is-grey">1</span>
                    </a>
                </div>
                
                <div class="control">
                    <a class="tags has-addons" href="/tags/cookie-%E4%B8%8E-webstorage%E7%9A%84%E5%8C%BA%E5%88%AB/">
                        <span class="tag">cookie 与 webstorage的区别</span>
                        <span class="tag is-grey">1</span>
                    </a>
                </div>
                
                <div class="control">
                    <a class="tags has-addons" href="/tags/hexo/">
                        <span class="tag">hexo</span>
                        <span class="tag is-grey">2</span>
                    </a>
                </div>
                
                <div class="control">
                    <a class="tags has-addons" href="/tags/hexo-theme-matery/">
                        <span class="tag">hexo-theme-matery</span>
                        <span class="tag is-grey">1</span>
                    </a>
                </div>
                
                <div class="control">
                    <a class="tags has-addons" href="/tags/lightgallery-js/">
                        <span class="tag">lightgallery.js</span>
                        <span class="tag is-grey">1</span>
                    </a>
                </div>
                
                <div class="control">
                    <a class="tags has-addons" href="/tags/vue/">
                        <span class="tag">vue</span>
                        <span class="tag is-grey">2</span>
                    </a>
                </div>
                
                <div class="control">
                    <a class="tags has-addons" href="/tags/vue-admin-template/">
                        <span class="tag">vue-admin-template</span>
                        <span class="tag is-grey">1</span>
                    </a>
                </div>
                
                <div class="control">
                    <a class="tags has-addons" href="/tags/vue%E5%BC%82%E6%AD%A5%E5%8A%A0%E8%BD%BD%E6%A8%A1%E5%9D%97/">
                        <span class="tag">vue异步加载模块</span>
                        <span class="tag is-grey">1</span>
                    </a>
                </div>
                
                <div class="control">
                    <a class="tags has-addons" href="/tags/vue%E7%BB%84%E4%BB%B6/">
                        <span class="tag">vue组件</span>
                        <span class="tag is-grey">1</span>
                    </a>
                </div>
                
                <div class="control">
                    <a class="tags has-addons" href="/tags/%E5%89%8D%E7%AB%AF%E9%9D%A2%E8%AF%95/">
                        <span class="tag">前端面试</span>
                        <span class="tag is-grey">3</span>
                    </a>
                </div>
                
                <div class="control">
                    <a class="tags has-addons" href="/tags/%E5%8E%BB%E5%93%AA%E5%84%BF%E7%BD%91/">
                        <span class="tag">去哪儿网</span>
                        <span class="tag is-grey">1</span>
                    </a>
                </div>
                
                <div class="control">
                    <a class="tags has-addons" href="/tags/%E6%95%B0%E7%BB%84/">
                        <span class="tag">数组</span>
                        <span class="tag is-grey">1</span>
                    </a>
                </div>
                
            </div>
        </div>
    </div>
</div>
        
        
        <div class="column-right-shadow is-hidden-widescreen ">
            
            <!-- 个人信息-目录 -->


    <div class="card widget" id="toc">
        <div class="card-content">
            <div class="menu">
                <h3 class="menu-label">
                    目录
                </h3>
                <ul class="menu-list"><li>
        <a class="is-flex" href="#概览">
        <span class="has-mr-6">1</span>
        <span>概览</span>
        </a></li><li>
        <a class="is-flex" href="#数据类型和结构">
        <span class="has-mr-6">2</span>
        <span>数据类型和结构</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#1-动态类型">
        <span class="has-mr-6">2.1</span>
        <span>1. 动态类型</span>
        </a></li><li>
        <a class="is-flex" href="#2-数据类型">
        <span class="has-mr-6">2.2</span>
        <span>2. 数据类型</span>
        </a></li><li>
        <a class="is-flex" href="#内置对象">
        <span class="has-mr-6">2.3</span>
        <span>内置对象</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#严格模式">
        <span class="has-mr-6">3</span>
        <span>严格模式</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#为某个script标签开启严格模式">
        <span class="has-mr-6">3.1</span>
        <span>为某个script标签开启严格模式</span>
        </a></li><li>
        <a class="is-flex" href="#为某个函数开启严格模式">
        <span class="has-mr-6">3.2</span>
        <span>为某个函数开启严格模式</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#相等性判断">
        <span class="has-mr-6">4</span>
        <span>相等性判断</span>
        </a></li><li>
        <a class="is-flex" href="#作用域">
        <span class="has-mr-6">5</span>
        <span>作用域</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#全局作用域">
        <span class="has-mr-6">5.1</span>
        <span>全局作用域</span>
        </a></li><li>
        <a class="is-flex" href="#局部作用域">
        <span class="has-mr-6">5.2</span>
        <span>局部作用域</span>
        </a></li><li>
        <a class="is-flex" href="#作用域链">
        <span class="has-mr-6">5.3</span>
        <span>作用域链</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#闭包-Closures">
        <span class="has-mr-6">6</span>
        <span>闭包(Closures)</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#一个示例">
        <span class="has-mr-6">6.1</span>
        <span>一个示例</span>
        </a></li><li>
        <a class="is-flex" href="#闭包解释">
        <span class="has-mr-6">6.2</span>
        <span>闭包解释</span>
        </a></li><li>
        <a class="is-flex" href="#立即执行函数表达式">
        <span class="has-mr-6">6.3</span>
        <span>立即执行函数表达式</span>
        </a></li><li>
        <a class="is-flex" href="#用闭包模拟私有方法">
        <span class="has-mr-6">6.4</span>
        <span>用闭包模拟私有方法</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#内存机制">
        <span class="has-mr-6">7</span>
        <span>内存机制</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#为什么会有栈内存和堆内存之分">
        <span class="has-mr-6">7.1</span>
        <span>为什么会有栈内存和堆内存之分</span>
        </a></li><li>
        <a class="is-flex" href="#垃圾回收机制">
        <span class="has-mr-6">7.2</span>
        <span>垃圾回收机制</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#清除方式">
        <span class="has-mr-6">7.2.1</span>
        <span>清除方式</span>
        </a></li></ul></li></ul></li><li>
        <a class="is-flex" href="#原型-prototype">
        <span class="has-mr-6">8</span>
        <span>原型(prototype)</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#原型链">
        <span class="has-mr-6">8.1</span>
        <span>原型链</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#对象创建方式">
        <span class="has-mr-6">9</span>
        <span>对象创建方式</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#1-Object构造函数方式">
        <span class="has-mr-6">9.1</span>
        <span>1. Object构造函数方式</span>
        </a></li><li>
        <a class="is-flex" href="#2-对象字面量方式">
        <span class="has-mr-6">9.2</span>
        <span>2. 对象字面量方式</span>
        </a></li><li>
        <a class="is-flex" href="#3-工厂模式">
        <span class="has-mr-6">9.3</span>
        <span>3. 工厂模式</span>
        </a></li><li>
        <a class="is-flex" href="#4-构造函数方式">
        <span class="has-mr-6">9.4</span>
        <span>4. 构造函数方式</span>
        </a></li><li>
        <a class="is-flex" href="#5-原型创建对象模式">
        <span class="has-mr-6">9.5</span>
        <span>5. 原型创建对象模式</span>
        </a></li><li>
        <a class="is-flex" href="#6-组合使用构造函数模式和原型模式">
        <span class="has-mr-6">9.6</span>
        <span>6. 组合使用构造函数模式和原型模式</span>
        </a></li><li>
        <a class="is-flex" href="#7-动态原型模式">
        <span class="has-mr-6">9.7</span>
        <span>7. 动态原型模式</span>
        </a></li><li>
        <a class="is-flex" href="#8-寄生构造函数方式">
        <span class="has-mr-6">9.8</span>
        <span>8. 寄生构造函数方式</span>
        </a></li><li>
        <a class="is-flex" href="#9-稳妥构造函数方式">
        <span class="has-mr-6">9.9</span>
        <span>9. 稳妥构造函数方式</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#并发模型和事件循环-event-loop">
        <span class="has-mr-6">10</span>
        <span>并发模型和事件循环(event loop)</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#1-运行时概念">
        <span class="has-mr-6">10.1</span>
        <span>1. 运行时概念</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#栈">
        <span class="has-mr-6">10.1.1</span>
        <span>栈</span>
        </a></li><li>
        <a class="is-flex" href="#堆">
        <span class="has-mr-6">10.1.2</span>
        <span>堆</span>
        </a></li><li>
        <a class="is-flex" href="#队列">
        <span class="has-mr-6">10.1.3</span>
        <span>队列</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#2-事件循环">
        <span class="has-mr-6">10.2</span>
        <span>2. 事件循环</span>
        </a></li><li>
        <a class="is-flex" href="#3-绝不阻塞">
        <span class="has-mr-6">10.3</span>
        <span>3. 绝不阻塞</span>
        </a></li></ul></li></ul>
            </div>
        </div>
    </div>

            
            <!-- 最近/最新的文章 -->
<div class="card widget">
    <div class="card-content">
        <h3 class="menu-label">
            最新文章
        </h3>
        
        <article class="media">
            
            <a href="/posts/7358.html" class="media-left">
                <p class="image is-64x64">
                    <img class="thumbnail" src="https://cn.vuejs.org/images/logo.png" alt="component组件嵌套，导致页面重复渲染，重复请求的bug">
                </p>
            </a>
            
            <div class="media-content">
                <div class="content">
                    <div><time class="has-text-grey is-size-7 is-uppercase" datetime="2020-05-23T02:18:20.000Z">2020-05-23</time></div>
                    <a href="/posts/7358.html" class="title has-link-black-ter is-size-6 has-text-weight-normal">component组件嵌套，导致页面重复渲染，重复请求的bug</a>
                    <p class="is-size-7 is-uppercase">
                        <a class="has-link-grey -link" href="/categories/vue/">vue</a>
                    </p>
                </div>
            </div>
        </article>
        
        <article class="media">
            
            <a href="/posts/2b18.html" class="media-left">
                <p class="image is-64x64">
                    <img class="thumbnail" src="https://cn.vuejs.org/images/logo.png" alt="vue异步加载模块">
                </p>
            </a>
            
            <div class="media-content">
                <div class="content">
                    <div><time class="has-text-grey is-size-7 is-uppercase" datetime="2020-05-22T23:18:18.000Z">2020-05-23</time></div>
                    <a href="/posts/2b18.html" class="title has-link-black-ter is-size-6 has-text-weight-normal">vue异步加载模块</a>
                    <p class="is-size-7 is-uppercase">
                        <a class="has-link-grey -link" href="/categories/vue/">vue</a>
                    </p>
                </div>
            </div>
        </article>
        
        <article class="media">
            
            <a href="/posts/54f1.html" class="media-left">
                <p class="image is-64x64">
                    <img class="thumbnail" src="https://panjiachen.gitee.io/vue-element-admin-site/home.png" alt="vue-admin-template模板添加tagsview">
                </p>
            </a>
            
            <div class="media-content">
                <div class="content">
                    <div><time class="has-text-grey is-size-7 is-uppercase" datetime="2020-05-02T16:22:02.000Z">2020-05-03</time></div>
                    <a href="/posts/54f1.html" class="title has-link-black-ter is-size-6 has-text-weight-normal">vue-admin-template模板添加tagsview</a>
                    <p class="is-size-7 is-uppercase">
                        <a class="has-link-grey -link" href="/categories/vue/">vue</a>
                    </p>
                </div>
            </div>
        </article>
        
        <article class="media">
            
            <a href="/posts/1d48.html" class="media-left">
                <p class="image is-64x64">
                    <img class="thumbnail" src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1051132835,1344326547&amp;fm=26&amp;gp=0.jpg" alt="关于 hexo 对文章渲染 {{ }} 解析的问题">
                </p>
            </a>
            
            <div class="media-content">
                <div class="content">
                    <div><time class="has-text-grey is-size-7 is-uppercase" datetime="2020-05-02T09:40:49.000Z">2020-05-02</time></div>
                    <a href="/posts/1d48.html" class="title has-link-black-ter is-size-6 has-text-weight-normal">关于 hexo 对文章渲染 {{ }} 解析的问题</a>
                    <p class="is-size-7 is-uppercase">
                        <a class="has-link-grey -link" href="/categories/hexo/">hexo</a>
                    </p>
                </div>
            </div>
        </article>
        
        <article class="media">
            
            <a href="/posts/6659.html" class="media-left">
                <p class="image is-64x64">
                    <img class="thumbnail" src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1102488500,1890914533&amp;fm=26&amp;gp=0.jpg" alt="初级前端综合面试题-3">
                </p>
            </a>
            
            <div class="media-content">
                <div class="content">
                    <div><time class="has-text-grey is-size-7 is-uppercase" datetime="2020-04-26T05:14:51.000Z">2020-04-26</time></div>
                    <a href="/posts/6659.html" class="title has-link-black-ter is-size-6 has-text-weight-normal">初级前端综合面试题-3</a>
                    <p class="is-size-7 is-uppercase">
                        <a class="has-link-grey -link" href="/categories/%E5%89%8D%E7%AB%AF/">前端</a> / <a class="has-link-grey -link" href="/categories/%E5%89%8D%E7%AB%AF/%E9%9D%A2%E8%AF%95/">面试</a>
                    </p>
                </div>
            </div>
        </article>
        
    </div>
</div>
            
            <!-- 个人信息-归档 -->
<div class="card widget">
    <div class="card-content">
        <div class="menu">
        <h3 class="menu-label">
            归档
        </h3>
        <ul class="menu-list">
        
        <li>
            <a class="level is-marginless" href="/archives/2020/05/">
                <span class="level-start">
                    <span class="level-item">五月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">4</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2020/04/">
                <span class="level-start">
                    <span class="level-item">四月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">2</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2020/03/">
                <span class="level-start">
                    <span class="level-item">三月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">8</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2020/01/">
                <span class="level-start">
                    <span class="level-item">一月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">1</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2019/12/">
                <span class="level-start">
                    <span class="level-item">十二月 2019</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">2</span>
                </span>
            </a>
        </li>
        
        </ul>
        </div>
    </div>
</div>
            
        </div>
        
    </div>


                
    

    

    

    


    <div class="column 11 is-4-tablet is-4-desktop is-3-widescreen is-hidden-touch is-hidden-desktop-only has-order-3 column-right ">
        
        <!-- 个人信息-目录 -->


    <div class="card widget" id="toc">
        <div class="card-content">
            <div class="menu">
                <h3 class="menu-label">
                    目录
                </h3>
                <ul class="menu-list"><li>
        <a class="is-flex" href="#概览">
        <span class="has-mr-6">1</span>
        <span>概览</span>
        </a></li><li>
        <a class="is-flex" href="#数据类型和结构">
        <span class="has-mr-6">2</span>
        <span>数据类型和结构</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#1-动态类型">
        <span class="has-mr-6">2.1</span>
        <span>1. 动态类型</span>
        </a></li><li>
        <a class="is-flex" href="#2-数据类型">
        <span class="has-mr-6">2.2</span>
        <span>2. 数据类型</span>
        </a></li><li>
        <a class="is-flex" href="#内置对象">
        <span class="has-mr-6">2.3</span>
        <span>内置对象</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#严格模式">
        <span class="has-mr-6">3</span>
        <span>严格模式</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#为某个script标签开启严格模式">
        <span class="has-mr-6">3.1</span>
        <span>为某个script标签开启严格模式</span>
        </a></li><li>
        <a class="is-flex" href="#为某个函数开启严格模式">
        <span class="has-mr-6">3.2</span>
        <span>为某个函数开启严格模式</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#相等性判断">
        <span class="has-mr-6">4</span>
        <span>相等性判断</span>
        </a></li><li>
        <a class="is-flex" href="#作用域">
        <span class="has-mr-6">5</span>
        <span>作用域</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#全局作用域">
        <span class="has-mr-6">5.1</span>
        <span>全局作用域</span>
        </a></li><li>
        <a class="is-flex" href="#局部作用域">
        <span class="has-mr-6">5.2</span>
        <span>局部作用域</span>
        </a></li><li>
        <a class="is-flex" href="#作用域链">
        <span class="has-mr-6">5.3</span>
        <span>作用域链</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#闭包-Closures">
        <span class="has-mr-6">6</span>
        <span>闭包(Closures)</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#一个示例">
        <span class="has-mr-6">6.1</span>
        <span>一个示例</span>
        </a></li><li>
        <a class="is-flex" href="#闭包解释">
        <span class="has-mr-6">6.2</span>
        <span>闭包解释</span>
        </a></li><li>
        <a class="is-flex" href="#立即执行函数表达式">
        <span class="has-mr-6">6.3</span>
        <span>立即执行函数表达式</span>
        </a></li><li>
        <a class="is-flex" href="#用闭包模拟私有方法">
        <span class="has-mr-6">6.4</span>
        <span>用闭包模拟私有方法</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#内存机制">
        <span class="has-mr-6">7</span>
        <span>内存机制</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#为什么会有栈内存和堆内存之分">
        <span class="has-mr-6">7.1</span>
        <span>为什么会有栈内存和堆内存之分</span>
        </a></li><li>
        <a class="is-flex" href="#垃圾回收机制">
        <span class="has-mr-6">7.2</span>
        <span>垃圾回收机制</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#清除方式">
        <span class="has-mr-6">7.2.1</span>
        <span>清除方式</span>
        </a></li></ul></li></ul></li><li>
        <a class="is-flex" href="#原型-prototype">
        <span class="has-mr-6">8</span>
        <span>原型(prototype)</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#原型链">
        <span class="has-mr-6">8.1</span>
        <span>原型链</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#对象创建方式">
        <span class="has-mr-6">9</span>
        <span>对象创建方式</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#1-Object构造函数方式">
        <span class="has-mr-6">9.1</span>
        <span>1. Object构造函数方式</span>
        </a></li><li>
        <a class="is-flex" href="#2-对象字面量方式">
        <span class="has-mr-6">9.2</span>
        <span>2. 对象字面量方式</span>
        </a></li><li>
        <a class="is-flex" href="#3-工厂模式">
        <span class="has-mr-6">9.3</span>
        <span>3. 工厂模式</span>
        </a></li><li>
        <a class="is-flex" href="#4-构造函数方式">
        <span class="has-mr-6">9.4</span>
        <span>4. 构造函数方式</span>
        </a></li><li>
        <a class="is-flex" href="#5-原型创建对象模式">
        <span class="has-mr-6">9.5</span>
        <span>5. 原型创建对象模式</span>
        </a></li><li>
        <a class="is-flex" href="#6-组合使用构造函数模式和原型模式">
        <span class="has-mr-6">9.6</span>
        <span>6. 组合使用构造函数模式和原型模式</span>
        </a></li><li>
        <a class="is-flex" href="#7-动态原型模式">
        <span class="has-mr-6">9.7</span>
        <span>7. 动态原型模式</span>
        </a></li><li>
        <a class="is-flex" href="#8-寄生构造函数方式">
        <span class="has-mr-6">9.8</span>
        <span>8. 寄生构造函数方式</span>
        </a></li><li>
        <a class="is-flex" href="#9-稳妥构造函数方式">
        <span class="has-mr-6">9.9</span>
        <span>9. 稳妥构造函数方式</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#并发模型和事件循环-event-loop">
        <span class="has-mr-6">10</span>
        <span>并发模型和事件循环(event loop)</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#1-运行时概念">
        <span class="has-mr-6">10.1</span>
        <span>1. 运行时概念</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#栈">
        <span class="has-mr-6">10.1.1</span>
        <span>栈</span>
        </a></li><li>
        <a class="is-flex" href="#堆">
        <span class="has-mr-6">10.1.2</span>
        <span>堆</span>
        </a></li><li>
        <a class="is-flex" href="#队列">
        <span class="has-mr-6">10.1.3</span>
        <span>队列</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#2-事件循环">
        <span class="has-mr-6">10.2</span>
        <span>2. 事件循环</span>
        </a></li><li>
        <a class="is-flex" href="#3-绝不阻塞">
        <span class="has-mr-6">10.3</span>
        <span>3. 绝不阻塞</span>
        </a></li></ul></li></ul>
            </div>
        </div>
    </div>

        
        <!-- 最近/最新的文章 -->
<div class="card widget">
    <div class="card-content">
        <h3 class="menu-label">
            最新文章
        </h3>
        
        <article class="media">
            
            <a href="/posts/7358.html" class="media-left">
                <p class="image is-64x64">
                    <img class="thumbnail" src="https://cn.vuejs.org/images/logo.png" alt="component组件嵌套，导致页面重复渲染，重复请求的bug">
                </p>
            </a>
            
            <div class="media-content">
                <div class="content">
                    <div><time class="has-text-grey is-size-7 is-uppercase" datetime="2020-05-23T02:18:20.000Z">2020-05-23</time></div>
                    <a href="/posts/7358.html" class="title has-link-black-ter is-size-6 has-text-weight-normal">component组件嵌套，导致页面重复渲染，重复请求的bug</a>
                    <p class="is-size-7 is-uppercase">
                        <a class="has-link-grey -link" href="/categories/vue/">vue</a>
                    </p>
                </div>
            </div>
        </article>
        
        <article class="media">
            
            <a href="/posts/2b18.html" class="media-left">
                <p class="image is-64x64">
                    <img class="thumbnail" src="https://cn.vuejs.org/images/logo.png" alt="vue异步加载模块">
                </p>
            </a>
            
            <div class="media-content">
                <div class="content">
                    <div><time class="has-text-grey is-size-7 is-uppercase" datetime="2020-05-22T23:18:18.000Z">2020-05-23</time></div>
                    <a href="/posts/2b18.html" class="title has-link-black-ter is-size-6 has-text-weight-normal">vue异步加载模块</a>
                    <p class="is-size-7 is-uppercase">
                        <a class="has-link-grey -link" href="/categories/vue/">vue</a>
                    </p>
                </div>
            </div>
        </article>
        
        <article class="media">
            
            <a href="/posts/54f1.html" class="media-left">
                <p class="image is-64x64">
                    <img class="thumbnail" src="https://panjiachen.gitee.io/vue-element-admin-site/home.png" alt="vue-admin-template模板添加tagsview">
                </p>
            </a>
            
            <div class="media-content">
                <div class="content">
                    <div><time class="has-text-grey is-size-7 is-uppercase" datetime="2020-05-02T16:22:02.000Z">2020-05-03</time></div>
                    <a href="/posts/54f1.html" class="title has-link-black-ter is-size-6 has-text-weight-normal">vue-admin-template模板添加tagsview</a>
                    <p class="is-size-7 is-uppercase">
                        <a class="has-link-grey -link" href="/categories/vue/">vue</a>
                    </p>
                </div>
            </div>
        </article>
        
        <article class="media">
            
            <a href="/posts/1d48.html" class="media-left">
                <p class="image is-64x64">
                    <img class="thumbnail" src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1051132835,1344326547&amp;fm=26&amp;gp=0.jpg" alt="关于 hexo 对文章渲染 {{ }} 解析的问题">
                </p>
            </a>
            
            <div class="media-content">
                <div class="content">
                    <div><time class="has-text-grey is-size-7 is-uppercase" datetime="2020-05-02T09:40:49.000Z">2020-05-02</time></div>
                    <a href="/posts/1d48.html" class="title has-link-black-ter is-size-6 has-text-weight-normal">关于 hexo 对文章渲染 {{ }} 解析的问题</a>
                    <p class="is-size-7 is-uppercase">
                        <a class="has-link-grey -link" href="/categories/hexo/">hexo</a>
                    </p>
                </div>
            </div>
        </article>
        
        <article class="media">
            
            <a href="/posts/6659.html" class="media-left">
                <p class="image is-64x64">
                    <img class="thumbnail" src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1102488500,1890914533&amp;fm=26&amp;gp=0.jpg" alt="初级前端综合面试题-3">
                </p>
            </a>
            
            <div class="media-content">
                <div class="content">
                    <div><time class="has-text-grey is-size-7 is-uppercase" datetime="2020-04-26T05:14:51.000Z">2020-04-26</time></div>
                    <a href="/posts/6659.html" class="title has-link-black-ter is-size-6 has-text-weight-normal">初级前端综合面试题-3</a>
                    <p class="is-size-7 is-uppercase">
                        <a class="has-link-grey -link" href="/categories/%E5%89%8D%E7%AB%AF/">前端</a> / <a class="has-link-grey -link" href="/categories/%E5%89%8D%E7%AB%AF/%E9%9D%A2%E8%AF%95/">面试</a>
                    </p>
                </div>
            </div>
        </article>
        
    </div>
</div>
        
        <!-- 个人信息-归档 -->
<div class="card widget">
    <div class="card-content">
        <div class="menu">
        <h3 class="menu-label">
            归档
        </h3>
        <ul class="menu-list">
        
        <li>
            <a class="level is-marginless" href="/archives/2020/05/">
                <span class="level-start">
                    <span class="level-item">五月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">4</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2020/04/">
                <span class="level-start">
                    <span class="level-item">四月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">2</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2020/03/">
                <span class="level-start">
                    <span class="level-item">三月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">8</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2020/01/">
                <span class="level-start">
                    <span class="level-item">一月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">1</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2019/12/">
                <span class="level-start">
                    <span class="level-item">十二月 2019</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">2</span>
                </span>
            </a>
        </li>
        
        </ul>
        </div>
    </div>
</div>
        
        
    </div>


            </div>
        </div>
    </section>
    <footer class="footer">
    <div class="container">
        <div class="level">
            <div class="level-start has-text-centered-mobile">
                <!-- <a class="footer-logo is-block has-mb-6" href="/">
                    
                    <img src="https://cdn.jsdelivr.net/gh/foxhuli229/cdn@1.5/images/foxlogo.png" alt="JavaScript之再学习" height="28">
                    
                </a> -->
                <p class="is-size-7">

                    
                    <!-- 不蒜子统计 -->
                    <span id="busuanzi_container_site_uv">
                        ❤️ 感谢 <span id="busuanzi_value_site_uv">0</span> 位小伙伴
                        的 <span id="busuanzi_value_page_pv">0</span> 次陪伴
                    </span>
                    

                    
                        <br>
                        <span id="sitetime">载入运行时间...</span>
                        <script>
                            function siteTime() {
                                var seconds = 1000;
                                var minutes = seconds * 60;
                                var hours = minutes * 60;
                                var days = hours * 24;
                                var years = days * 365;
                                var today = new Date();
                                var startYear = "2020";
                                var startMonth = "3";
                                var startDate = "08";
                                var startHour = "0";
                                var startMinute = "0";
                                var startSecond = "0";
                                var todayYear = today.getFullYear();
                                var todayMonth = today.getMonth() + 1;
                                var todayDate = today.getDate();
                                var todayHour = today.getHours();
                                var todayMinute = today.getMinutes();
                                var todaySecond = today.getSeconds();
                                var t1 = Date.UTC(startYear, startMonth, startDate, startHour, startMinute, startSecond);
                                var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
                                var diff = t2 - t1;
                                var diffYears = Math.floor(diff / years);
                                var diffDays = Math.floor((diff / days) - diffYears * 365);
                                var diffHours = Math.floor((diff - (diffYears * 365 + diffDays) * days) / hours);
                                var diffMinutes = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours) /
                                    minutes);
                                var diffSeconds = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours -
                                    diffMinutes * minutes) / seconds);
                                if (startYear == todayYear) {
                                    // document.getElementById("year").innerHTML = todayYear;
                                    document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffDays + " 天 " + diffHours +
                                        " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                                } else {
                                    // document.getElementById("year").innerHTML = startYear + " - " + todayYear;
                                    document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffYears + " 年 " + diffDays +
                                        " 天 " + diffHours + " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                                }
                            }
                            setInterval(siteTime, 1000);
                        </script>
                    

                    <!-- 站长统计 -->
                    
                        <br>
                        <script type="text/javascript">
                            document.write(unescape("%3Cspan id='cnzz_stat_icon_1278694833'%3E%3C/span%3E%3Cscript src='https://s9.cnzz.com/z_stat.php%3Fid%3D1278694833%26online%3D1%26show%3Dline' type='text/javascript'%3E%3C/script%3E"));
                        </script>
                    

                    <!-- 域名信息 -->
                    
                    <br>
                    <span id="icp"><img src="https://cdn.jsdelivr.net/gh/foxhuli229/cdn@1.0/source/medias/icp.png"
                            style="vertical-align: text-bottom;" />
                        <a href="http://beian.miit.gov.cn/state/outPortal/loginPortal.action" target="_blank">渝ICP备18015404号</a>
                    </span>
                    

                    <br>
                    <!-- 版权信息 -->
                    
                    &copy; 2020 Fox&nbsp;
                    Powered by <a href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a> & <a
                        href="https://github.com/ppoffice/hexo-theme-icarus" target="_blank" rel="noopener">Icarus</a>
                    & <a href="https://foxhuli.top/" target="_blank" rel="noopener">Fox</a>
                </p>
            </div>

            <!-- 访问链接 -->
            <div class="level-end">
                
                <div class="field has-addons is-flex-center-mobile has-mt-5-mobile is-flex-wrap is-flex-middle">
                    
                    <p class="control">
                        <a class="button is-white is-large" target="_blank"
                            rel="noopener" title="掘金"
                            href="https://juejin.im/user/5d36544b6fb9a07efd474ae0/">
                            
                                
                                    <span>掘</span>
                                
                            
                        </a>
                    </p>
                    
                    <p class="control">
                        <a class="button is-white is-large" target="_blank"
                            rel="noopener" title="简书"
                            href="https://www.jianshu.com/u/e1f2e756cb5e/">
                            
                                
                                    <span>简</span>
                                
                            
                        </a>
                    </p>
                    
                    <p class="control">
                        <a class="button is-white is-large" target="_blank"
                            rel="noopener" title="知乎"
                            href="https://www.zhihu.com/people/hu-li-60-36-4/activities/">
                            
                                
                                    <span>知</span>
                                
                            
                        </a>
                    </p>
                    
                    <p class="control">
                        <a class="button is-white is-large" target="_blank"
                            rel="noopener" title="CDSN"
                            href="https://blog.csdn.net/xiaohuli_hyr/">
                            
                                
                                    <span>C</span>
                                
                            
                        </a>
                    </p>
                    
                    <p class="control">
                        <a class="button is-white is-large" target="_blank"
                            rel="noopener" title="My GitHub"
                            href="https://github.com/foxhuli229?tab=repositories">
                            
                                
                                    <i class="fab fa-github"></i>
                                
                            
                        </a>
                    </p>
                    
                </div>
                
            </div>

        </div>
    </div>
</footer>
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/moment@2.22.2/min/moment-with-locales.min.js"></script>
<script>moment.locale("zh-CN");</script>


<script>
var IcarusThemeSettings = {
    site: {
        url: 'https://foxhuli.top',
        external_link: {"enable":true,"exclude":[]}
    },
    article: {
        highlight: {
            clipboard: true,
            fold: 'unfolded'
        }
    }
};
</script>


<script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.4/dist/clipboard.min.js" defer></script>





<script src="/js/animation.js"></script>



<script src="https://cdn.jsdelivr.net/npm/lightgallery@1.6.8/dist/js/lightgallery.min.js" defer></script>
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js" defer></script>
<script src="/js/gallery.js" defer></script>



<div id="outdated">
    <h6>Your browser is out-of-date!</h6>
    <p>Update your browser to view this website correctly. <a id="btnUpdateBrowser" href="http://outdatedbrowser.com/">Update
            my browser now </a></p>
    <p class="last"><a href="#" id="btnCloseUpdateBrowser" title="Close">&times;</a></p>
</div>
<script src="https://cdn.jsdelivr.net/npm/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.js" defer></script>
<script>
    document.addEventListener("DOMContentLoaded", function () {
        outdatedBrowser({
            bgColor: '#f25648',
            color: '#ffffff',
            lowerThan: 'flex'
        });
    });
</script>





<a id="back-to-top" title="回到顶端" href="javascript:;">
    <i class="fas fa-chevron-up"></i>
</a>
<script src="/js/back-to-top.js" defer></script>














<script src="/js/main.js" defer></script>

    
    <div class="searchbox ins-search">
    <div class="searchbox-container ins-search-container">
        <div class="searchbox-input-wrapper">
            <input type="text" class="searchbox-input ins-search-input" placeholder="想要查找什么..." />
            <span class="searchbox-close ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="searchbox-result-wrapper ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
    (function (window) {
        var INSIGHT_CONFIG = {
            TRANSLATION: {
                POSTS: '文章',
                PAGES: '页面',
                CATEGORIES: '分类',
                TAGS: '标签',
                UNTITLED: '(无标题)',
            },
            CONTENT_URL: '/content.json',
        };
        window.INSIGHT_CONFIG = INSIGHT_CONFIG;
    })(window);
</script>
<script src="/js/insight.js" defer></script>
<link rel="stylesheet" href="/css/search.css">
<link rel="stylesheet" href="/css/insight.css">
    
    

    <script src="https://cdn.jsdelivr.net/gh/foxhuli229/cdn@1.0/source/libs/jquery/jquery.min.js"></script>

    <!-- 引用 鼠标点击实现文字效果 -->
    <script src="https://cdn.jsdelivr.net/gh/foxhuli229/cdn@1.0/source/js/click_show_text.js"></script>

    <!-- //只在桌面版网页启用特效 -->
    <!-- <script type="text/javascript">
        var windowWidth = $(window).width();
        if (windowWidth > 768) {
            document.write('<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/foxhuli229/cdn@1.0/source/js/sakura.js"><\/script>');
        }
    </script> -->

     <!-- 实现 鼠标划过彩虹星星掉落跟随效果 -->
     <!-- <script src="https://cdn.jsdelivr.net/gh/foxhuli229/cdn@1.0/source/js/cursor.js"></script> -->

      <!-- tidio聊天工具 -->
    <!-- <script src="//code.tidio.co/hcpgs6vy7zc60cdqvx033yuue25y9vgj.js" async></script> -->

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
        tex2jax: {
            inlineMath: [ ["$","$"], ["\\(","\\)"] ],
            skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'],
            processEscapes: true
        }
    });
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax();
        for (var i = 0; i < all.length; ++i)
            all[i].SourceElement().parentNode.className += ' has-jax';
    });
</script>
<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register('/sw.js?t=1590368958168')
    .then(function () {console.log('ServiceWorker Register Successfully.')})
    .catch(function (e) {console.error(e)});
}
</script><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/shizuku.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true},"log":false});</script></body>
</html>